#include "formtargettest.h"
#include "ui_formtargettest.h"

#include "tasktargettest.h"

formTargetTest::formTargetTest(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::formTargetTest)
{
    ui->setupUi(this);

    QRegExp re("^[0-9a-f]+$");
    QRegExpValidator *hex = new QRegExpValidator(re, this);

    ui->brkaddr->setValidator(hex);

    wk = new taskTargetTest;
    connect(wk, SIGNAL(outLog(QString)), this, SLOT(rcvLog(QString)));
    wk->start();
}

formTargetTest::~formTargetTest()
{
    delete wk;
    wk = nullptr;
    delete ui;
}

void formTargetTest::setParam(QString p)
{
    if (wk)
        wk->params = p;
}

void formTargetTest::rcvLog(QString s)
{
    emit outLog(s);
}

void formTargetTest::on_pbReadReg_clicked()
{
    wk->putReq(0, ui->regid->text());
}

void formTargetTest::on_pbAddBrk_clicked()
{
    wk->putReq(1, ui->brkaddr->text()); //添加软断点
}

void formTargetTest::on_pbReadMem_clicked()
{
    QString a, s;

    a = ui->memaddr->text();
    s = ui->memsize->text();

    wk->putReq(2, a + ":" + s);//读存储
}

void formTargetTest::on_pbWriteReg_clicked()
{
    wk->putReq(3, ui->regid->text());
}

void formTargetTest::on_pbDelBrk_clicked()
{
    wk->putReq(4, ui->brkaddr->text());
}

void formTargetTest::on_pbpoll_clicked()
{
    wk->putReq(5, "");
}

void formTargetTest::on_pbRun_clicked()
{
    wk->putReq(6, "");
}

void formTargetTest::on_pbHalt_clicked()
{
    wk->putReq(7, "");
}

void formTargetTest::on_pbReadReg_CacheMaybe_clicked()
{
    wk->putReq(8, ui->regid->text());
}

void formTargetTest::on_pbHReset_clicked()
{
    wk->putReq(9, "");
}

void formTargetTest::on_pbsresetr_clicked()
{
    wk->putReq(10, "");
}

void formTargetTest::on_pbsreseth_clicked()
{
    wk->putReq(11, "");
}
